export default {
  namespaced: true,
  state: {
    // 当前的播放进度
    progress: 0,
    // 是否在拖拽进度条
    isDrag: false,
    // 总时间
    duration: 0,
    // 是否在播放
    playing: false,
    // 当前播放歌曲的下标
    currentSongIndex: -1,
    // 播放歌单
    playSongList: [],
  },
  getters: {
    // 当前的歌曲信息
    currentSong(state){
      if(state.currentSongIndex >= 0){
        return state.playSongList[state.currentSongIndex];
      }else{
        return {};
      }
    }
  },
  mutations: {
    // 设置播放进度
    setProgress(state, payload){
      state.progress = payload;
    },
    // 设置是否拖拽
    setDrag(state, payload){
      state.isDrag = payload;
    },
    setDuration(state, payload){
      state.duration = payload;
    },
    // 设置播放状态
    setPlaying(state){
      state.playing = !state.playing;
    },
    // 设置播放音乐的下标
    setCurrentSongIndex(state, payload){
      // 修改下标
      state.currentSongIndex = payload;
      // 播放音乐
      state.playing = true;
    },
    // 设置播放列表
    setPlaySongList(state, payload){
      state.playSongList = JSON.parse(JSON.stringify(payload));
    }
  }
}